﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>
</head>
<body>

<div class="container-fluid " style="margin-top: 20px">
    <#include "../common/top.ftl"/>

    <div class="row">
        <div class="col-lg-2">
            <#assign menu="customerPool"/>
        <#--左侧菜单-->
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-lg-10">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">客户池管理</h1>
                </div>
            </div>
        <#-- 高级查询 -->
            <form class="form-inline" id="searchForm" action="/customerPool/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <input type="hidden" name="pageSize" id="pageSize" value="20">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入姓名/电话">
                </div>
                <button type="submit" class="btn btn-primary">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>

            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>时间</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>电话</th>
                    <th>家庭职业</th>
                    <th>意向课程</th>
                    <th>来源</th>
                    <th>旧营销人员</th>
                    <th>备注</th>
                    <th>操作</th>
                </tr>
            <#-- Freemark指令做循环迭代 -->
                <#list ro.list as entity>
                    <tr>
                        <td>${(entity_index + 1)!}</td>
                        <td>${(entity.inputTime?string("yyyy/MM/dd"))!}</td>
                        <td>${(entity.name)!}</td>
                        <td>${(entity.genderName)!}</td>
                        <td>${(entity.age)!}</td>
                        <td>${(entity.tel)!}</td>
                        <td>${(entity.job)!}</td>
                        <td>${(entity.curriculum.title)!}</td>
                        <td>${(entity.source.title)!}</td>
                        <td>${(entity.seller.name)!}</td>
                        <td>${(entity.remark)!}</td>
                        <td>

                            <a role="button" class="btn btn-warning btn-xs transfermeBtn" data-json='${(entity.json)!}'>
                                <span class="glyphicon glyphicon-transfer"></span> 移交给我
                            </a>
                            <@shiro.hasAnyRoles name="admin,客户经理">
                                <a role="button" class="btn btn-warning btn-xs transferBtn" data-json='${(entity.json)!}'>
                                    <span class="glyphicon glyphicon-transfer"></span> 移交
                                </a>
                            </@shiro.hasAnyRoles>
                        </td>
                    </tr>
                </#list>
            </table>

        <#--分页-->
            <#include "../common/page.ftl" />
        </div>
    </div>
</div>


<#-- 客户移交 -->
<div class="modal fade" id="transferModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">客户移交</h4>
            </div>
            <div class="modal-body">
                <!--填充编辑界面-->
                <form class="form-horizontal" action="/customerTransferHistory/save.do" method="post" id="transferForm">
                    <input type="hidden" name="customer.id"/>
                    <input type="hidden" name="oldSeller.id"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">客户姓名：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" id="cname" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">旧营销人员：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" id="oldSeller" readonly/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">新营销人员：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="newSeller.id">

                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">移交原因：</label>
                        <div class="col-lg-6">
                            <textarea type="text" class="form-control" name="reason" cols="10"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary transferSubmitBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {

        $(".transfermeBtn").click(function () {
            //清空原来的新销售员
            $("#transferForm select[name='newSeller.id']").html("");
            var json = $(this).data("json");
            //回填其他数据
            $("#transferForm input[name='customer.id']").val(json.id);
            //回显当前客户
            $("#cname").val(json.name);
            //回显旧销售
            $("#oldSeller").val(json.sellerName);
            $("#transferForm input[name='oldSeller.id']").val(json.sellerId);

            $("<option value='" + <@shiro.principal property='id'/> + "'>" + '<@shiro.principal property='name'/>' + "</option>")
                    .appendTo("#transferForm select[name='newSeller.id']");
            $("#transferModal").modal("show");
        });


        //移交按钮点击事件
        $(".transferBtn").click(function () {
            var json = $(this).data("json");
            //发送请求,查询当前可移交的新销售员
            $.get("/customerPool/queryNewSeller.do", function (data) {
                //清空原来的新销售员
                $("#transferForm select[name='newSeller.id']").html("");
                //重新填充
                $.each(data, function (index, ele) {
                    $("<option value='" + ele.id + "'>" + ele.name + "</option>")
                            .appendTo("#transferForm select[name='newSeller.id']");
                });
                // 必须放在响应函数中,先完成了异步加载,才能回显

            }, "json");
            //回填其他数据
            $("#transferForm input[name='customer.id']").val(json.id);
            $("#transferForm input[name='oldSeller.id']").val(json.sellerId);
            //回显当前客户
            $("#cname").val(json.name);
            //回显旧销售
            $("#oldSeller").val(json.sellerName);
            $("#transferModal").modal("show");
        });

        //ajax提交移交表单
        $(".transferSubmitBtn").click(function () {
            $("#transferForm").ajaxSubmit(function (data) {
                if(data.success){
                    $.messager.alert("温馨提示","移交成功");
                    setTimeout(function () {
                        window.location.href="/customerTransferHistory/list.do";
                    },1500);
                }else {
                    msg(data.msg);
                }
            })
        });





    });



</script>
</body>
</html>